﻿using System.Linq;
using _3Sixty.Maverick.Models;

namespace ThreeSixty.Maverick
{
    /// <summary>
    /// This class contains utilities for handling threads.
    /// </summary>
    public class ThreadUtilities
    {
        private readonly ThreesixtyMaverickEntities entities = new ThreesixtyMaverickEntities();

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IQueryable<Thread> ThreadsGet()
        {
            return entities.Threads;
        }

        /// <summary>
        /// This method gets a thread by its unique ID.
        /// </summary>
        public Thread ThreadByIDGet(int id)
        {
            return entities.Threads.Include("Messages").FirstOrDefault(t => t.ThreadID == id);
        }

        /// <summary>
        /// 
        /// </summary>
        public void Save()
        {
            entities.SaveChanges();
        }
    }
}